package com.gaga.crm;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import redis.clients.jedis.Jedis;

@SpringBootTest
@RunWith(SpringRunner.class)
public class JedisTester {
    private Jedis jedis;

    @Before
    public void setup() {
        //连接 redis 服务器，127.0.0.1:6379
        jedis = new Jedis("127.0.0.1", 6379);
        //权限认证，指定密码
        jedis.auth("zyj");
    }

    @Test
    public void testString() {
        //-----添加数据----------
        jedis.set("name", "Super");//向 key-->name 中放入了 value-->Super
        System.out.println(jedis.get("name"));//执行结果：Super

        jedis.append("name", "Gaga"); //拼接
        System.out.println(jedis.get("name"));

        jedis.del("name"); //删除某个键
        System.out.println(jedis.get("name")); //null

        //设置多个键值对
        jedis.mset("name", "SuperGaga", "age", "22", "from", "CSGO");
        jedis.incr("age"); //进行加 1 操作
        System.out.println(jedis.get("name") + "-" + jedis.get("age") + "-" + jedis.get("from"));
    }
}
